package code;

import java.util.HashMap;
import java.util.HashSet;

public class KthToLast_day04 {
    public static void main(String[] args) {
       ListNode head = new ListNode(0);head.next = null;
       ListNode node1 = new ListNode(1);node1.next = null;head.next=node1;
       ListNode node2 = new ListNode(2);node2.next = null;node1.next=node2;
       ListNode node3 = new ListNode(3);node3.next = null;node2.next=node3;
       ListNode node4 = new ListNode(4);node4.next = null;node3.next=node4;
       ListNode node5 = new ListNode(5);node5.next = null;node4.next=node5;
       ListNode node6 = new ListNode(6);node6.next = null;node5.next=node6;
       ListNode node7 = new ListNode(7);node7.next = null;node6.next=node7;
       ListNode node8 = new ListNode(8);node8.next = null;node7.next=node8;
       ListNode p=head;
       int k=8;
       HashMap<Integer,Integer> map=new HashMap<Integer,Integer>();
        int key=0;
        while(p!=null){
            map.put(key,p.val);
            key++;
            p=p.next;
        }
        System.out.println(map.get(k-1));
    }
    public static class ListNode {
        int val;
       ListNode next;
        ListNode() {}
        ListNode(int val) { this.val = val; }
        ListNode(int val,ListNode next) { this.val = val; this.next = next; }
    }
}
